﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace taobaoSpider
{
    public partial class wxuserFrm : Form
    {
        WXWS.MpUserInfo user = new WXWS.MpUserInfo();
        string exePath = Application.StartupPath;
        public wxuserFrm()
        {
            InitializeComponent();
        }

        public wxuserFrm(WXWS.MpUserInfo user)
        {
            InitializeComponent();
            this.user = user;
            txtRealFromUserName.Text = user.realFromUserName;
            txtRealToUserName.Text = user.realToUserName;
            txtFromUserName.Text = user.fromUserName;
            txtLocation.Text = user.location;
            txtAge.Text = user.age.ToString();
            txtSex.Text = user.sex;
            txtSubscribe.Text = user.subscribe;
            string imgFile = exePath+"\\MpIcon\\" + txtFromUserName.Text + ".jpg";
            if (File.Exists(imgFile))
            {
                txtUserIcon.Image = Image.FromFile(imgFile);
            }
            else
            {
                txtUserIcon.Image = null;
            }
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            WXWS.wx_wsSoapClient client = new WXWS.wx_wsSoapClient();
            this.user.realFromUserName = txtRealFromUserName.Text;
            this.user.age = Convert.ToInt32(txtAge.Text);
            this.user.sex = txtSex.Text;
            this.user.location = txtLocation.Text;
            client.UpdateMpUser(this.user);
        }

        private void btnUploadIcon_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "JPG files (*.jpg)|*.jpg|PNG files (*.png)|*.png";
            string saveImgPath = exePath + "\\MpIcon\\" + txtFromUserName.Text + ".jpg";
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                string imgFile = ofd.FileName;
                Image img = Image.FromFile(imgFile);
                img = img.GetThumbnailImage(48, 48, null, IntPtr.Zero);
                img.Save(saveImgPath);
                this.txtUserIcon.Image = img;
            }
        }
    }
}
